package Thread;

/**
 * Created by Administrator on 2018/4/10.
 */
public class RunnableImpl implements Runnable {

    private Thread thread;

    @Override
    public void run() {
        System.out.println("Running " + thread.getName());
        try {
            for (int i = 4; i > 0; i--) {
                System.out.println("Thread: " + thread.getName() + ", " + i);
                // 让线程睡眠一会
                Thread.sleep(50);
            }
        } catch (InterruptedException e) {
            System.out.println("Thread " + thread.getName() + " interrupted.");
        }
        System.out.println("Thread " + thread.getName() + " exiting.");

    }

    public void start(String threadName) {
        System.out.println("Starting " + threadName);
        if (thread == null) {
            thread = new Thread(this, threadName);
            thread.start();
        }
    }


    public static void main(String[] args) {
        new RunnableImpl().start("Thread-1");
        new RunnableImpl().start("Thread-2");
    }
}
